/*
    SEL - Simple DirectMedia Layer Extension Library
    Copyright (C) 2001 Matej Knopp <knopp@users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __sel_mouse_h__
#define __sel_mouse_h__

#include "sdl.h"

namespace SEL
{

//!  This class can be used to determine the mouse position and state
//!  and for setting / getting the mouse cursor.
class Mouse
{
public:
	//! Retrieve the current state of the mouse
	/*!
	  \return the current button state returned as a button bitmask
	  of OR'd values:
	  - SDL::BUTTON_LMASK
	  - SDL::BUTTON_MMASK
	  - SDL::BUTTON_RMASK
	  
	  \param x, y references to the variables in which the current mouse
	   position will be stored.
	 */
	static Uint8 mouseState (int &x, int &y);
	
	//! Retrieve the current state of the mouse
	/*!
	  \return the current button state returned as a button bitmask
	  of OR'd values:
	  - SDL::BUTTON_LMASK
	  - SDL::BUTTON_MMASK
	  - SDL::BUTTON_RMASK
	  
	  \param x, y references to the variables which are set to the
          mouse deltas since the last call to Mouse::relativeMouseState ().
	 */
	static Uint8 relativeMouseState (int &x, int &y);
	
	//! Set the position of the mouse cursor.
	/*!
	  \note This function generates a mouse motion event.
	  
	  \param x, y new coordinates of the mouse cursor.
	 */
	static void warpMouse (Uint16 x, Uint16 y);
	
	//! Set the currently active cursor to the specified one.
	/*!
	  \param cursor the mouse cursor created with the Mouse::createCursor ()
	  function.
	  \sa cursor (), createCursor ()
	 */
	static void setCursor (SDL::Cursor *cursor);
	
	//! Return the currently active cursor.
	/*!
	 \return the currently active mouse cursor.
	 */
	static SDL::Cursor *cursor ();

	//! Create a cursor using the specified data and mask (in MSB format).
	/*!
	  The cursor width must be a multiple of 8 bits.
	  
	  The cursor is created in black and white according to the
	  following:
	  \verbatim
	  data  mask   resulting pixel on screen
	   0     1      White
	   1     1      Black
	   0     0      Transparent
	   1     0      Inverted color if possible, black if not
	  \endverbatim
	  Cursors created with this function must be freed with 
	  the Mouse::freeCursor () function.
	  
	  \param data, mask the data and the mask described as above.
	  \param w, h dimensions of the cursor.
	  \param hot_x, hot_y coordinates of the hot spot.
	  \sa freeCursor(), setCursor (), cursor ()
	 */
	static SDL::Cursor *createCursor (Uint8 *data, Uint8 *mask, 
					  int w, int h, int hot_x, int hot_y);

	//! Free the cursor previously created with Mouse::createCursor ()
	/*!
	  \param cursor the mouse cursor to be freed.
	  \sa createCursor ()	  
	 */
	static void freeCursor (SDL::Cursor *cursor);

	//! Toggle whether or not the cursor is shown on the screen.
	/*!
	  The cursor start off displayed, but can be turned off.
	  \return true if the cursor was being displayed before the
	  call, or 0 if it was not. You can query the current state by
	  passing a \a toggle value of -1.
	  \param toggle whether to display the cursor or not.
	 */
	static bool showCursor (int toggle);
};

//////////////////////////////////////////////////////////////
/////////////////////  INLINE FUNCTIONS  /////////////////////
//////////////////////////////////////////////////////////////

inline Uint8
Mouse::mouseState (int &x, int &y)
{
	return SDL::GetMouseState (&x, &y);
}
	
inline Uint8 
Mouse::relativeMouseState (int &x, int &y)
{
	return SDL::GetRelativeMouseState (&x, &y);
}
	
inline void 
Mouse::warpMouse (Uint16 x, Uint16 y)
{
	SDL::WarpMouse (x, y);
}
	
inline void 
Mouse::setCursor (SDL::Cursor *cursor)
{
	SDL::SetCursor (cursor);
}

inline SDL::Cursor *
Mouse::cursor ()
{
	return SDL::GetCursor ();
}

inline SDL::Cursor* 
Mouse::createCursor (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
{
	return SDL::CreateCursor (data, mask, w, h, hot_x, hot_y);
}

inline void 
Mouse::freeCursor (SDL::Cursor *cursor)
{
	SDL::FreeCursor (cursor);
}

inline bool 
Mouse::showCursor (int toggle)
{
	return SDL::ShowCursor (toggle);
}

} // namespace SEL

#endif // __sel_mouse_h__
